<template>
  <el-card
<<<<<<< HEAD
    ><el-table :data="showdata" stripe style="width: 100%">
=======
    ><el-table :data="tableData" stripe style="width: 100%">
>>>>>>> 7d520118954f103433f5074ad63a16f5b63acf51
      <el-table-column
        :prop="item.prop"
        :label="item.label"
        :width="item.width"
        v-for="(item, index) in options"
        :key="index"
      >
        <template v-slot="{ row }" v-if="item.prop === 'status'"
          ><el-switch v-model="row.statusbool" @change="changestatus(row)"
        /></template>
        <template #default="{ row }" v-else-if="item.prop === `action`">
<<<<<<< HEAD
          <el-button type="warning" size="small" @click="jump(row)"
=======
          <el-button type="warning" size="small" @click="clickdeleteuser(row)"
>>>>>>> 7d520118954f103433f5074ad63a16f5b63acf51
            >批改</el-button
          >
        </template>
      </el-table-column></el-table
    >
    <el-pagination
      v-model:currentPage="queryForm.pageIndex"
      v-model:page-size="queryForm.pageSize1"
      :page-sizes="[5, 10, 20, 50]"
      :small="small"
      :disabled="disabled"
      :background="background"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
  /></el-card>
  <Dialog v-model="dialogVisible" @inituserlist="inigetuser" />
  <Edit v-model="editVisible" @inituserlist="inigetuser" :rowvalue="rowvalue" />
</template>

<script setup>
import { reactive, ref } from 'vue'
import { getanswer } from '@/api/answer'
import { Search } from '@element-plus/icons-vue'
import {
  mydata,
  getuser,
  getuserfromusername,
  edituserstatus,
  deleteuser
} from '@/api/user'
import { options } from './options'
import { ElMessage } from 'element-plus'
import Dialog from './components/dialog.vue'
import Edit from './components/edit.vue'
<<<<<<< HEAD
import router from '@/router'
=======
>>>>>>> 7d520118954f103433f5074ad63a16f5b63acf51
const tableData = ref([])

const queryForm = ref({
  name: '',
  pageIndex: 1,
  pageSize: 1000,
  pageSize1: 10,
  role: 1
})

const total = ref(10)
const dialogVisible = ref(false) //   添加用户是否弹出
const editVisible = ref(false) //   编辑是否弹出
const rowvalue = ref({}) //  编辑信息的原信息
<<<<<<< HEAD
const showdata = ref([])
=======
>>>>>>> 7d520118954f103433f5074ad63a16f5b63acf51
//  更新table
const inigetuser = async () => {
  const res = await getanswer(queryForm.value)
  tableData.value = res.data.data.list
  console.log(res)
  for (let i = 0; i < tableData.value.length; i++) {
<<<<<<< HEAD
    if (tableData.value[i].status !== 1) {
=======
    if (tableData.value[i].status !== 2) {
>>>>>>> 7d520118954f103433f5074ad63a16f5b63acf51
      tableData.value.splice(i, 1)
      i = i - 1
    }
  }
<<<<<<< HEAD
  total.value = tableData.value.length
  for (
    let i = (queryForm.value.pageIndex - 1) * queryForm.value.pageSize1;
    i < queryForm.value.pageIndex * queryForm.value.pageSize1;
    i++
  ) {
    if (tableData.value[i]) showdata.value.push(tableData.value[i])
  }
=======
>>>>>>> 7d520118954f103433f5074ad63a16f5b63acf51
}
inigetuser()

const handleSizeChange = (pageSize1) => {
  queryForm.value.pageIndex = 1
  queryForm.value.pageSize1 = pageSize1
<<<<<<< HEAD
  showdata.value = []
  for (
    let i = (queryForm.value.pageIndex - 1) * queryForm.value.pageSize1;
    i < queryForm.value.pageIndex * queryForm.value.pageSize1;
    i++
  ) {
    if (tableData.value[i]) showdata.value.push(tableData.value[i])
  }
  //  inigetuser()
=======
  inigetuser()
>>>>>>> 7d520118954f103433f5074ad63a16f5b63acf51
}

const handleCurrentChange = (pagenum) => {
  queryForm.value.pageIndex = pagenum
<<<<<<< HEAD
  showdata.value = []
  for (
    let i = (queryForm.value.pageIndex - 1) * queryForm.value.pageSize1;
    i < queryForm.value.pageIndex * queryForm.value.pageSize1;
    i++
  ) {
    if (tableData.value[i]) showdata.value.push(tableData.value[i])
  }
  //  inigetuser()
}

const jump = (row) => {
  console.log(row.id)
  router.push({ name: 'judge', params: { id: row.id } })
=======
  inigetuser()
}

//  添加用户
const handleadduser = () => {
  dialogVisible.value = true
}
// 编辑用户
const edituser = (row) => {
  rowvalue.value = JSON.parse(JSON.stringify(row))
  editVisible.value = true
}
//  修改用户状态
const changestatus = (info) => {
  edituserstatus(info.id)
  ElMessage({
    showClose: true,
    message: '用户状态修改成功',
    type: 'success'
  })
}
// 删除用户
const clickdeleteuser = (info) => {
  deleteuser(info.id)
  ElMessage({
    showClose: true,
    message: '成功删除用户',
    type: 'success'
  })
  inigetuser()
>>>>>>> 7d520118954f103433f5074ad63a16f5b63acf51
}
</script>

<style lang="scss" scoped>
.header {
  padding-bottom: 16px;
  box-sizing: border-box;
}
</style>
